<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport"
			content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>AIT国际汽车改装展</title>
		<script src="./js/responsive.js" type="text/javascript" charset="utf-8"></script>
		<meta name='keywords' content='' />
		<meta name='description' content='' />
		<meta name="author" content="" />
		<link rel="stylesheet" type="text/css" href="./css/public.css?1.0.0" />
		<link rel="stylesheet" type="text/css" href="./layer2/need/layer.css" />
		<link rel="stylesheet" type="text/css" href="./css/mobileSelect.css" />
		<link rel="stylesheet" type="text/css" href="./css/picker.css" />
		<link rel="stylesheet" type="text/css" href="./css/swiper.min.css" />
		<script type="text/javascript">
			document.write('<link rel="stylesheet" type="text/css" href="./css/style.css?v=' + new Date().getTime() + '"/>');
		</script>
		<style>
			.error{
				padding-top:0.1rem;
				font-size: 0.24rem;
				color:#dd0117
			}
			.swiper-pagination-bullet{
				width:6px;
				height:6px;
				background:rgba(0,0,0,0);
				border:1px solid #fff;
				opacity: 1;
			}
			.swiper-pagination-bullet-active{
				background:rgba(255,255,255,1);
			}
			.content .form{
				padding-top:0.3rem;
			}
		</style>
	</head>
	<body>
		<div class="main s-skin" id="app">
			<div class="content" >
				<div class="swiper-container" id="swiper-container-banner">
					<div class="swiper-wrapper" >
						<div class="swiper-slide ">
							<div class="ellipsis"><img src="./icon/1_12.jpg" ></div>
						</div>
					</div>
					<div class="swiper-pagination"></div>
				</div>
				<div class="form">
					<form name="myform" onsubmit="return false" action="##" method="post">
						<div class="con-lis">
							<div class="lis">
								<label class="lab"><span>*</span>请选择参观日期</label>
								<div class="posit-fast select_type">
									<input class="inp-lb select tb_select_type"  id="select" type="text" name="date" placeholder="请点击选择参观日期" readonly>
									<input class="inp-lb hidden" type="text" name="dateA" placeholder="请点击选择参观日期" readonly>
								</div>
							</div>
							<div class="lis">
								<label class="lab"><span>*</span>身份证（必填）</label>
								<div class="posit-fast">
									<input class="inp-lb" id="sfz" name="sfz" type="text" placeholder="应防疫要求，请填写18位身份证号码" maxlength="18">
								</div>
							</div>
							<div class="lis">
								<label class="lab"><span>*</span>姓名</label>
								<div class="posit-fast">
									<input class="inp-lb" id="name" name="name" type="text" placeholder="请填写联系人姓名" maxlength="10">
								</div>
							</div>
							<div class="lis">
								<label class="lab"><span>*</span>所在省、市（单选）</label>
								<div class="posit-fast">
									<input class="inp-lb select province select-value" id="province" name="province" type="text" placeholder="请点击选择所在省、市" maxlength="18" readonly>
								</div>
							</div>
							<div class="lis">
								<label class="lab"><span>*</span>客户类型(单选)</label>
								<div class="posit-fast">
									<input class="inp-lb select" id="mold" name="moldtype" type="text" placeholder="请点击选择客户类型" maxlength="18" readonly>
									<div class="cke-cdO otherA hidden">
										<input class="inp-lb" id="customerType" name="customerType" type="text" placeholder="请填写您所属客户类型" maxlength="30">
									</div>
								</div>
							</div>
							<div>
								<div class="cke-cd hidden">
									<div class="lis">
										<label class="lab"><span>*</span>公司全称</label>
										<div class="posit-fast">
											<input class="inp-lb company" id="companyName" name="companyName" type="text" placeholder="请填写公司名称" maxlength="20">
										</div>
									</div>
									<div class="lis">
										<label class="lab"><span>*</span>职务</label>
										<div class="posit-fast">
											<input class="inp-lb company" id="dutie" name="dutie" type="text" placeholder="请填写您的职务" maxlength="20">
										</div>
									</div>
								</div>
								<div class="cke-cd hidden">
									<div class="lis">
										<label class="lab"><span>*</span>汽车品牌</label>
										<div class="posit-fast">
											<input class="inp-lb" id="brand" name="brand" type="text" placeholder="请填写汽车品牌" maxlength="20">
										</div>
									</div>
								</div>
							</div>
							<div class="lis">
								<label class="lab"><span>*</span>您了解展会的途径(单选）</label>
								<div class="posit-fast">
									<input class="inp-lb select" id="channel" name="channel" type="text" placeholder="请点击选择您了解展会的途径" maxlength="18" readonly>
									<div class="cke-cdO otherB hidden">
										<input class="inp-lb" id="otherchannel" name="otherchannel" type="text" placeholder="请填写您了解到展会的途径" maxlength="30">
									</div>
								</div>
							</div>
							<div class="lis">
								<button class="btn submit" >提交资料</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script src="./js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/utils.js?v1.0.1" type="text/javascript" charset="utf-8"></script>
		<script src="./layer2/layer.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/province.js?v1.0.1" type="text/javascript" charset="utf-8"></script>
		<script src="./js/jquery.new.select.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/mobileSelect.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/request.js?v1.0.6" type="text/javascript" charset="utf-8"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js" type="text/javascript"></script>
		<script type="text/javascript" charset="utf-8">
			var phone = getUrlParam('phone');
			var cid = getUrlParam('f');
			var openid = getCookie('openid');
			var leadId = getCookie('leadid');
			var uid = getCookie('uid');
			var code = getUrlParam('code');
			var firstonclick = true;
			var hostUrl = window.location.protocol+"//"+window.location.host;
			function replaceParamVal(paramName,replaceWith) {
				 var oUrl = this.location.href.toString();
				 var re=eval('/('+ paramName+'=)([^&]*)/gi');
				 var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
				 this.location = nUrl;
				 window.location.href=nUrl
			}
			if(code){
				replaceParamVal('code','')
			}
			if(!uid){
				location.replace('index.html?f='+cid)
				setCookie('uid','',-1)
			}else{
				if(uid != cid){
					replaceParamVal('f',uid)
				}
				if(openid){
					apply()
				}else{
					polling()
				}
			}
			//banner
			if($('.swiper-slide').length>1){
				var mySwiper = new Swiper('#swiper-container-banner', {
					pagination: '.swiper-pagination',
					slidesPerView: 1,
					observer:true,//修改swiper自己或子元素时，自动初始化swiper 
					observeParents:true,//修改swiper的父元素时，自动初始化swiper 
					paginationClickable: true,
					autoplayDisableOnInteraction : false,
					autoplay : 5000,
					loop: true
				});
			}
			$(".company").focus(function(){
				var viewTop = $(window).scrollTop(),            // 可视区域顶部
				    viewBottom = viewTop + window.innerHeight;  // 可视区域底部
					setTimeout(function(){
						$(window).scrollTop(window.innerHeight);
						// alert(window.innerHeight/2)
					},300)
					
			});
			var browser = {
			    versions: function () {
			        var u = navigator.userAgent, app = navigator.appVersion;
			        return {         //移动终端浏览器版本信息
			            trident: u.indexOf('Trident') > -1, //IE内核
			            presto: u.indexOf('Presto') > -1, //opera内核
			            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
			            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
			            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
			            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
			            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
			            iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
			            iPad: u.indexOf('iPad') > -1, //是否iPad
			            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
			        };
			    }(),
			    language: (navigator.browserLanguage || navigator.language).toLowerCase()
			}
			if (browser.versions.mobile) {//判断是否是移动设备打开。browser代码在下面
			        var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
			        if (ua.match(/MicroMessenger/i) == "micromessenger") {
			                //在微信中打开
							getshare()
			        }
			        if (ua.match(/WeiBo/i) == "weibo") {
			                //在新浪微博客户端打开
			        }
			        if (ua.match(/QQ/i) == "qq") {
			                //在QQ空间打开
			        }
			        if (browser.versions.ios) {
			                //是否在IOS浏览器打开
							
			        } 
			        if(browser.versions.android){
			                //是否在安卓浏览器打开
			        }
			} else {
			        //否则就是PC浏览器打开
					console.log('pc')
			}
			function getshare() {
				var params = {
					url:window.location.href
				}
				ajaxGet('apply/getShareAccess',params, function(res) {
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					if(res.data){
						wx.config({
							debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。   
							appId: res.data.appId, // 必填，公众号的唯一标识
							timestamp: res.data.timestamp, // 必填，生成签名的时间戳
							nonceStr: res.data.noncestr, // 必填，生成签名的随机串
							signature: res.data.signature, // 必填，签名，见附录1
							jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','hideMenuItems'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
						  });
						  wx.error(function (res) {
							//alert("失败："+res.msg);
						  });
						
						// wx.config 检测无误后，会进入到  ready 方法 。 注意type参数。微信多数的坐标体系都为gcj02
						  wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
							wx.hideMenuItems({
								menuList:[
									'menuItem:share:timeline',
									'menuItem:share:appMessage',
									'menuItem:copyUrl',
									  'menuItem:openWithQQBrowser',
									  'menuItem:openWithSafari',
									  'menuItem:share:qq',
									  'menuItem:share:QZone',
									  'menuItem:share:weiboApp',
									  'menuItem:share:facebook'],
							});
							wx.checkJsApi({
										jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
										success: function(res) {
											// 以键值对的形式返回，可用的api值true，不可用为false
											// 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
										}
									});
									//分享朋友圈
									wx.onMenuShareTimeline({
										title:'【点击报名】10月22-24日 AIT国际汽车改装展' , // 分享标题
										link: window.location.href, // 分享链接
										imgUrl: hostUrl + '/icon/logo.jpg', // 分享图标
										success: function () {
											// 用户确认分享后执行的回调函数
										},
										cancel: function () {
											// 用户取消分享后执行的回调函数
										}
									});
									 
									//分享朋友
									wx.onMenuShareAppMessage({
										title: '【点击报名】10月22-24日 AIT国际汽车改装展', // 分享标题
										desc: '东莞·广东现代国际展览中心', // 分享描述
										link: window.location.href, // 分享链接
										imgUrl: hostUrl + '/icon/logo.jpg', // 分享图标
										type: '', // 分享类型,music、video或link，不填默认为link
										dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
										success: function () {
											// 用户确认分享后执行的回调函数
										},
										cancel: function () {
											// 用户取消分享后执行的回调函数
										},
										fail:function(res){
											//alert(res);
										}
									});
						  });
					}
				},
				function(err){
					
				})
				
			}
			//是否报名
			function apply(){
				var params = {
					openId:openid
				}
				ajaxGet('apply/getApplyByOpenId',params, function(res) {
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					if(res.data.idcard && res.data.name && res.data.qrcode){
						url = encodeURI('committed.html?f='+res.data.id+'&v='+new Date().getTime());
						window.location = url;
					}
				},
				function(err){
					
				})
			}
			//根据id查询报名
			function polling(){
				var params = {
					id:uid
				}
				ajaxGet('apply/getById',params, function(res) {
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					if(res.data.idcard && res.data.name && res.data.qrcode){
						url = encodeURI('committed.html?f='+res.data.id+'&v='+new Date().getTime());
						location.replace(url)
					}
				},
				function(err){
					
				})
			}
			let list = [{
						id:1,
						name:'10月22日'
					},{
						id:2,
						name:'10月23日'
					},{
						id:3,
						name:'10月24日'
					}];
			let select = new pickerSelect({
				el:'select_type',
				type:"checkbox",
				list:list
			})
			$(".select_type").on('click',function(){
				select.click({
					val:$("input[name='dateA']").val(),
					callBack:function(res){
						$("input[name='dateA']").val(res.val)
					}
				})
			})
			var moldType = 0;
			var mold = ['改装店','修理厂','省市级经销商','批发商/门店','4S集团/单店','电商平台/网店','媒体\协会\达人','整车厂','车主','其他'];
			var mobileSelect = new MobileSelect({
			    trigger: '#mold',
			    title: '单项选择',
			    wheels: [
			                {data: mold}
			            ],
			    position:[0], //初始化定位 打开时默认选中的哪个 如果不填默认为0
			    transitionEnd:function(indexArr, data){
			        //console.log(data);
			    },
			    callback:function(indexArr, data){
					var _index = indexArr[0];
					if(data[0] == '车主') {
						$('.cke-cd').eq(1).show().siblings().hide();
						$('.otherA').hide();
						moldType = 1
					}else if(data[0] == '其他'){
						$('.cke-cd').siblings().hide();
						$('.otherA').show();
						moldType = 2
					}else{
						$('.cke-cd').eq(0).show().siblings().hide();
						$('.otherA').hide();
						moldType = 0
					}
					$('#mold').val(data[0])
					
			    }
			});
			var date = ['官方微信','厂商邀请','达人邀请','抖音','快手','朋友圈','微信群','短信','媒体','广告','其他'];
			var channelType = 0;
			var mobileSelect1 = new MobileSelect({
			    trigger: '#channel',
			    title: '单项选择',
			    wheels: [
			                {data: date}
			            ],
			    position:[0], //初始化定位 打开时默认选中的哪个 如果不填默认为0
			    transitionEnd:function(indexArr, data){
			        //console.log(data);
			    },
			    callback:function(indexArr, data){
					var _index = indexArr[0];
					if(data[0] == '其他'){
						$('.otherB').show()
						channelType = 1
					}else{
						$('.otherB').hide()
						channelType = 0
					}
					$('#channel').val(data[0])
			    }
			});
			/**
			 * 联动的picker
			 * 两级
			 */
			$('.select-value').mPicker({
				level: 2,
				dataJson: dataJson,
				Linkage: true,
				shadow: false,
				rows: 6,
				idDefault: true,
				splitStr: '-',
				header: '<div class="mPicker-header">省市联动选择</div>',
				confirm: function() {
					//更新json
					console.info($('.select-value').data('value1')+'-'+$('.select-value').data('value2'));
					$("#city").val($('.select-value').data('name1') + '-' + $('.select-value').data('name2'))
					//console.log($('.select-value').data('name1')+'-'+$('.select-value').data('name2'))
				},
				cancel: function() {
					//console.info($('.select-value').data('value1')+'-'+$('.select-value').data('value2'));
				}
			})
			$('.submit').on('click',function(){
				var _select = myform.date.value;
				var _sfz = myform.sfz.value;
				var _name = myform.name.value;
				var _province = myform.province.value;
				var _moldtype = myform.moldtype.value;
				var _companyname = myform.companyName.value;
				var _dutie = myform.dutie.value;
				var _brand = myform.brand.value;
				var _customertype = myform.customerType.value;
				var _channel = myform.channel.value;
				var _otherchannel = myform.otherchannel.value;
				
				if(!_select){
					error($('#select'),'请选择参观时间')
					return false
				}
				removerror($('#select'))
				if(!_sfz || _sfz.length != 18){
					error($('#sfz'),'请填写18位身份证号码')
					return false
				}
				if(!checkIdCardNo(_sfz)){
					error($('#sfz'),'请填写正确的身份证号码')
					return false
				}
				removerror($('#sfz'))
				if(!_name){
					error($('#name'),'请填写姓名')
					return false
				}
				removerror($('#name'))
				if(!_province){
					error($('#province'),'请选择省市')
					return false
				}
				removerror($('#province'))
				if(!_moldtype){
					error($('#mold'),'请选择客户类型')
					return false
				}
				removerror($('#mold'))
				if(moldType == 0){
					if(!_companyname){
						error($('#companyName'),'请填写公司名称')
						return false
					}
					removerror($('#companyName'))
					if(!_dutie){
						error($('#dutie'),'请填写职务')
						return false
					}
					removerror($('#dutie'))
				}else if(moldType == 1){
					if(!_brand){
						error($('#brand'),'请输入汽车品牌')
						return false
					}
					removerror($('#brand'))
				}else{
					if(!_customertype){
						error($('#customerType'),'请输入其他客户类型')
						return false
					}
					removerror($('#customerType'))
				}
				if(!_channel){
					error($('#channel'),'请选择您了解展会的途径')
					return false
				}
				removerror($('#channel'))
				if(channelType == 1){
					if(!_otherchannel){
						error($('#otherchannel'),'请填写您了解到展会的途径')
						return false
					}
					removerror($('#otherchannel'))
				}
				var params = {
					id:uid,
					phone:phone,
					leadId:leadId,
					canguantime:_select,
					idcard:_sfz,
					name:_name,
					sheng:_province.split('-')[0],
					shi:_province.split('-')[1],
					kehuleixing:_moldtype,
					zhanhuitujing:_channel,
				}
				if(openid){
					params.openId = openid
				}
				if(moldType == 0){
					params.company = _companyname
					params.job = _dutie
				}else if(moldType == 1){
					params.chezhuqichepinpai = _brand
				}else{
					params.kehuleixingQita = _customertype
				}
				if(channelType == 1){
					params.zhanhuitujingqitaQita = _otherchannel
				}
				if(!firstonclick){
					return false
				}
				firstonclick = false
				ajaxPost('apply/submit',JSON.stringify(params), function(res) {
					firstonclick = true
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					removerror($('#sfz'))
					url = encodeURI('committed.html?f='+res.data+'&v='+new Date().getTime());
					window.location = url;
					
				},
				function(err){
					firstonclick = true
					if(err.responseJSON.code == '5000008'){
						error($('#sfz'),err.responseJSON.msg)
						return
					}
					layer.open({
						content: err.responseJSON.msg,
						skin: 'msg',
						time: 3, //2秒后自动关闭
					});
				})
			})
			//检查身份证
			function checkIdCardNo (val) {
				var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				return pattern.test(val);
			};
			
			var u = navigator.userAgent, app = navigator.appVersion;
			        var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
			        $(document).ready(function(){
			                $("input").blur(function(){
			                        if (isIOS) {
			                              blurAdjust()
			                        }
			                });
			        });
			function blurAdjust(e){
			            setTimeout(()=>{
			                if(document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA'){
			                        return
			               }
			            let result = 'pc';
			            if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
			                    result = 'ios';
			            }else if(/(Android)/i.test(navigator.userAgent)) { //判断Android
			                    result = 'android';
			            }
			            if( result = 'ios' ){
			                   const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
							window.scrollTo(0, Math.max(scrollHeight - 1, 0))
			            }
			        },100);
			    }
			const iOS = /iPad|iPhone|iPod/.test(u);
			
			$("input").focus(function(){
			  setTimeout(() => {
				if (iOS) {
				  if (!/OS 11_[0-3]\D/.test(u)) {
					document.body.scrollTop = document.body.scrollHeight;   
				  }
				} else {
				  input.scrollIntoView(false);
				}
			  }, 300);
			});
			
		</script>
	</body>
</html>
